﻿using System;
using UnityEngine;

namespace ProjectMyFarmAndShe
{
    public class ChallengeData
    {
        public string Key { get; private set; }
        public string Publisher { get; private set; }
        public string Description { get; private set; }
        //用来记录当前日期
        public int CurrentDay { get; private set; }
        public bool Finished { get; private set; }
        
        //记录当前委托完成日期
        public int FinishedDay { get; set; }

        //解锁条件
        public Func<ChallengeData,bool> UnLockCondition;
        //完成条件
        private Func<bool> Condition;
        private Action<ChallengeData> FishedAction;
        
        public void OnFinished()
        {
            if (!Condition.Invoke())
            {
                Debug.Log("未达成条件");
                return;
            }

            Finished = true;
            FinishedDay = Global.Day.Value;
            FishedAction?.Invoke(this);
        }

        public ChallengeData WithKey(string key)
        {
            Key = key;
            return this;
        }

        public ChallengeData WithPublisher(string publisher)
        {
            Publisher = publisher;
            return this;
        }

        public ChallengeData WithDescription(string description)
        {
            Description = description;
            return this;
        }

        public ChallengeData WithCurrentDay(int day)
        {
            CurrentDay = day;
            return this;
        }

        public ChallengeData WithUnlock(Func<ChallengeData,bool> func)
        {
            UnLockCondition = func;
            return this;
        }

        public ChallengeData WithFinishedAction(Action<ChallengeData> action)
        {
            FishedAction = action;
            return this;
        }

        public ChallengeData WithFinished(bool finish)
        {
            Finished = finish;
            return this;
        }

        public ChallengeData WithCondition(Func<bool> func)
        {
            Condition = func;
            return this;
        }
    }
}